package cn.iocoder.yudao.module.bpm.service.oa.listener;

import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.mq.redis.core.stream.AbstractRedisStreamMessageListener;
import cn.iocoder.yudao.module.bpm.event.OaBpmProcessInstanceStatus;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOALeaveService;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOALeaveServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

@Slf4j
@Component
public class BpmOARedisConsumersListener extends AbstractRedisStreamMessageListener<OaBpmProcessInstanceStatus> {


    @Resource
    BpmOALeaveService leaveService;

    @Override // 监听器
    public void onMessage(OaBpmProcessInstanceStatus message) {
        if (!StrUtil.equals(message.getProcessDefinitionKey(),BpmOALeaveServiceImpl.PROCESS_KEY)) {
            log.info("[onMessage][消息内容({})]", message);
            return;
        }
        leaveService.updateLeaveStatus(Long.parseLong(message.getBusinessKey()), message.getStatus());
    }

}
